package com.obc.quantity;

import junit.framework.TestCase;

//Ensures correctness of measurement manipulation
public class TestQuantity extends TestCase {
	
	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	public void testConstructor() throws Exception {
		assertNotNull(feet(1));
	}

	public void testFeetToFeet() throws Exception {
		assertEquals(feet(1), new Quantity(1, Unit.FOOT));
	}
	
	public void testKiloToKilo() throws Exception {
		assertEquals(kilo(1), kilo(1));
	}

	public void testFeetToInches() throws Exception {
		assertEquals(feet(1), inch(12));
		assertEquals(feet(2), inch(24));
	}

	public void testKiloToGrams() throws Exception {
		assertEquals(kilo(1), gram(1000));
		assertEquals(kilo(2), gram(2000));
	}

	public void testAddFeetToFeet() throws Exception {
		assertEquals(feet(2), feet(1).add(feet(1)));
		assertEquals(feet(4), feet(3).add(feet(1)));
	}
	
	public void testAddKiloToKilo() throws Exception {
		assertEquals(kilo(2), kilo(1).add(kilo(1)));
		assertEquals(kilo(4), kilo(3).add(kilo(1)));
	}

	public void testAddFeetToInch() throws Exception {
		assertEquals(feet(2), feet(1).add(inch(12)));
	}
	
	public void testAddKiloToFeet()   {
		try{
			Quantity result = kilo(2).add(feet(5));
			fail("Incompatible Units Addition!");
		}catch(IncompatibleUnitsException e){
				assertNotNull(e);
		}
	}
	
	private Quantity feet(int value){
		return new Quantity(value, Unit.FOOT);
	}
	
	private Quantity inch(int value){
		return new Quantity(value, Unit.INCH);
	}

	private Quantity kilo(int value){
		return new Quantity(value, Unit.KILO);
	}
	
	private Quantity gram(int value){
		return new Quantity(value, Unit.GRAM);
	}
	
}











